﻿package com.designoutput.ui.controls
{
    import com.designoutput.event.NumberEvent;
    
    import flash.events.*;
    import flash.text.*;

    public class Input extends TextField
    {
        internal var value:String;

        public function Input(width:int, defaultVal:String, maxChars:int = 100)
        {
            this.value = defaultVal;
            this.defaultTextFormat = new TextFormat("Verdana,Helvetica,San-serif", 10, 0, null, null, null, null, null, "left");
            this.type = TextFieldType.INPUT;
            this.maxChars = maxChars;
            this.background = true;
            this.backgroundColor = 16777215;
            this.border = true;
            this.borderColor = 9474192;
            this.height = 16;
            this.width = width;
            this.addEventListener(KeyboardEvent.KEY_UP, this.Changed);
        }

        private function Changed(event:KeyboardEvent) : void
        {
            var val:* = Number(this.text);
            dispatchEvent(new NumberEvent(NumberEvent.VALUE_CHANGE, val));
        }

    }
}
